layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    
    $(function(){
    	$("body").find("input").focus();
    	$(".desc").click(function () {
			window.location.href = WEBAPP_ROOTPATH + "/pages/setup/setupLogin.html";
		});
    });
    
	// 监听提交
	form.on('submit(login)', function(data) {
		let btn =  $(this);
    	btn.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
		$.ajax({
			// 几个参数需要注意一下
			type : "POST",// 方法类型
			dataType : "json",// 预期服务器返回的数据类型
			url : "./login/loginIn",// url
			data : $(data.form).serialize(),
			success : function(result) {
				if(result.returnCode == 200){
					window.location.href = result.returnMsg;
				}else{
					layer.msg(result.returnMsg, {
	                    time:5000
	                });
	            	btn.text("登录").removeAttr("disabled").removeClass("layui-disabled");
				}
				return false;
			},
			error : function(result) {
				console.log(result);
				layer.msg(result.responseJSON.returnMsg, {
                    time:5000
                });
            	btn.text("登录").removeAttr("disabled").removeClass("layui-disabled");
            	return false;
			}
		});
		return false;
	});
    
    $(".verifyCode").on('click', function (e) {
    	var num = Math.random();
    	$(".verifyCode").attr("src", "./verifyCode/generateCode?random=" + num);
//    	$.post("../verifyCode/generateCode",{
//    	});
    });
    
    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
